//
//  HWAlertManager.m
//  kzyjsq
//
//  Created by 李含文 on 2018/12/4.
//  Copyright © 2018年 李含文. All rights reserved.
//

#import "HWAlertManager.h"
#import "SPAlertController.h"
//#import "NSMutableAttributedString+Category.h"

@implementation HWAlertManager


+ (void)hw_showSheet:(id _Nullable)title message:(id _Nullable)message actionTitles:(NSArray<NSString *> *)titles actionBlock:(void(^)(NSInteger index))actionBlock {
    if (titles.count == 0) {return;}
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:(UIAlertControllerStyleActionSheet)];
    for (int i = 0; i<titles.count; i++) {
        NSString *str = titles[i];
        UIAlertAction *action = [UIAlertAction actionWithTitle:str style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            actionBlock(i);
        }];
        [alert addAction:action];
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [alert addAction:cancel];
    [hw_getVisibleViewController() presentViewController:alert animated:YES completion:nil];
}

+ (void)hw_showAlert:(NSString * _Nullable)title message:(NSString * _Nullable)message actionTitles:(NSArray<NSString *> *)titles actionBlock:(void(^)(NSInteger index))actionBlock {
    if (titles.count == 0) {return;}
    SPAlertController *alert = [SPAlertController alertControllerWithTitle:title message:message preferredStyle:SPAlertControllerStyleAlert animationType:SPAlertAnimationTypeDefault];
    alert.titleColor = [UIColor blackColor];
    alert.titleFont = [UIFont boldSystemFontOfSize:17];
    alert.messageColor = [UIColor blackColor];
    alert.messageFont = [UIFont systemFontOfSize:14];
    
    SPAlertAction *cancel = [SPAlertAction actionWithTitle:@"取消" style:(SPAlertActionStyleDestructive) handler:nil];
    cancel.titleColor = [UIColor blackColor];
    cancel.titleFont = [UIFont systemFontOfSize:14];
    [alert addAction:cancel];
    
    for (int i = 0; i<titles.count; i++) {
        NSString *str = titles[i];
        SPAlertAction *action = [SPAlertAction actionWithTitle:str style:(SPAlertActionStyleDefault) handler:^(SPAlertAction * _Nonnull action) {
            actionBlock(i);
        }];
        action.titleColor = [UIColor redColor];
        action.titleFont = [UIFont systemFontOfSize:14];
        [alert addAction:action];
    }
    
    [hw_getVisibleViewController() presentViewController:alert animated:YES completion:nil];
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
//    //改变title的大小和颜色
//    NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title];
//    [titleAtt addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0, title.length)];
//    [titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor cc_colorWithHex:@"343434"] range:NSMakeRange(0, title.length)];
//    [alert setValue:titleAtt forKey:@"attributedTitle"];
//    //改变message的大小和颜色
//    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];
//    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, message.length)];
//    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor cc_colorWithHex:@"343434"] range:NSMakeRange(0, message.length)];
//    [alert setValue:messageAtt forKey:@"attributedMessage"];
//
//    for (int i = 0; i<titles.count; i++) {
//        NSString *str = titles[i];
//        UIAlertAction *action = [UIAlertAction actionWithTitle:str style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//            actionBlock(i);
//        }];
//        [action setValue:[UIColor cc_colorWithHex:@"E72822"] forKey:@"_titleTextColor"];
//        [alert addAction:action];
//    }
//    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消".cc_Localized style:(UIAlertActionStyleCancel) handler:nil];
//    //修改按钮
//    if ([cancel valueForKey:@"_titleTextColor"]) {
//
//    }
//    [cancel setValue:[UIColor cc_colorWithHex:@"343434"] forKey:@"_titleTextColor"];
//    [alert addAction:cancel];
//    [[CCAppTool getVisibleViewController] presentViewController:alert animated:YES completion:nil];
}

//+ (void)hw_showWarning {
//    SPAlertController *alert = [SPAlertController alertControllerWithTitle:CCLocalizedString(@"您可以尝试以下方式:") message:CCLocalizedString(@"") preferredStyle:SPAlertControllerStyleAlert animationType:SPAlertAnimationTypeDefault];
//    NSString *fist = @"发送邮件至 ".cc_Localized;
//    NSString *url = @"customerservice.id@miniso.com";
//    NSString *last = @"联系我们。".cc_Localized;
//    NSMutableAttributedString *att = [[NSString stringWithFormat:@"%@%@ %@", fist, url, last].cc_strAttribute cc_textColor:[UIColor colorWithRed:79/255.0 green:157/255.0 blue:248/255.0 alpha:1] range:NSMakeRange(fist.length, url.length)];
//    alert.attributedMessage = [att cc_font:[UIFont systemFontOfSize:14] range:att.rangeOfAll];
//    alert.minDistanceToEdges = 40;
//    alert.textAlignment = NSTextAlignmentLeft;
//    alert.titleColor = [UIColor cc_colorWithHex:@"343434"];
//    alert.titleFont = [UIFont boldSystemFontOfSize:17];
//    alert.messageColor = [UIColor cc_colorWithHex:@"343434"];
//    alert.messageFont = [UIFont systemFontOfSize:13];
//    SPAlertAction *cancel = [SPAlertAction actionWithTitle:CCLocalizedString(@"确定") style:(SPAlertActionStyleDestructive) handler:^(SPAlertAction * _Nonnull action) {
//        //        CCOrderDetailsVC *vc = [[CCOrderDetailsVC alloc] initWithOrderSn:self.orderSn isSourcePay:YES];
//        //        [self.navigationController pushViewController:vc animated:YES];
//    }];
//    cancel.titleColor = [UIColor cc_colorWithHex:@"343434"];
//    cancel.titleFont = [UIFont systemFontOfSize:14];
//    [alert addAction:cancel];
//    [[CCAppTool getVisibleViewController] presentViewController:alert animated:YES completion:nil];
//}
@end
